﻿using Mimas.Core.Current;
using Mimas.Framework.Shared.Data.DataTransferObjects;
using Mimas.Framework.Shared.Data.EnumObjects;
using System;
using System.Linq;

namespace Mimas.Framework.Server.DomainObjects.Mapping
{
    public static class FileArchiveMapping
    {
        public static FileArchive Map(FileArchiveDTO data)
        {
            FileArchive newItem = new FileArchive();

            newItem.Bytes = data.Bytes;
            newItem.Extension = data.Extension;
            newItem.Guid = data.Guid;
            newItem.Id = data.Id;
            newItem.Name = data.Name;
            newItem.Path = data.Path;

            if (data.Id == 0)
            {
                newItem.CreatedBy = UserInfo.CurrentUser.UserId;
                newItem.CreatedOn = DateTime.Now;
            }
            else
            {
                newItem.ModifiedBy = UserInfo.CurrentUser.UserId;
                newItem.ModifiedOn = DateTime.Now;
            }

            return newItem;
        }

        public static FileArchiveDTO Map(FileArchive data)
        {
            FileArchiveDTO newItem = new FileArchiveDTO();

            newItem.Bytes = data.Bytes;
            newItem.Extension = data.Extension;
            newItem.Guid = data.Guid;
            newItem.Id = data.Id;
            newItem.Name = data.Name;
            newItem.Path = data.Path;

            return newItem;
        }

        public static FileArchive[] Map(FileArchiveDTO[] data)
        {
            if (data == null || !data.Any()) return null;
            return data.Where(x => x != null).Select(x => Map(x)).ToArray();
        }

        public static FileArchiveDTO[] Map(FileArchive[] data)
        {
            if (data == null || !data.Any()) return null;
            return data.Where(x => x != null).Select(x => Map(x)).ToArray();
        }
    }
}
